package gaml.testing;

import static org.junit.Assert.*;

import gaml.error.GamlException;
import gaml.text.YamlLine;
import gaml.text.YamlText;

import java.io.File;
import java.io.IOException;

import org.junit.Test;


public class YamlTextTest {
	
	public static String parseString = "			aaabvvv	";
	public static String sampleParent = "aaa:\n\taaa1:bbb\n\taaa2:vvv\n\taaa3:ccc\nbbb:\n\tbbb1:eee";

	@Test
	public void testReadString () throws GamlException {
		YamlText yt = new YamlText ().read (sampleParent);
		
		assertEquals (6, yt.getSize ());
		
		assertEquals ("aaa2:vvv", yt.getValue (2));
		assertEquals (1, yt.getIdentation (3));
	}
	
	@Test
	public void testReadFile () throws IOException, GamlException {
		YamlText yt = new YamlText ();
		yt.read (new File ("c:\\work\\test.vbs"));
		assertEquals ("Set objShell = CreateObject (\"Wscript.Shell\")", yt.getValue (0));
		assertEquals (1, yt.getIdentation (1));
	}

	@Test
	public void testParseString () throws GamlException {
		assertEquals (3, new YamlLine (parseString, "	", 0).getIdent ());
		assertEquals (1, new YamlLine (parseString, "	", 2).getIdent ());
		assertEquals ("aaabvvv", new YamlLine (parseString, "	", 0).getValue ());
	}

	@Test
	public void testNewFormPart () throws GamlException {
		YamlText parent = new YamlText ().read (sampleParent);
		
		YamlText yt = new YamlText (parent, 4);
		
		assertEquals (1, yt.getSize ());
		assertEquals ("bbb1:eee", yt.getValue (0));
		assertEquals (0, yt.getIdentation (0));
	}
}